package kr.hkit.recoder_pro;

import kr.hkit.recoder_pro2.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

public class Main extends Activity {
	
		
		TextView mEllapse;
		ImageButton mImgNok;
		ImageButton mImgStop;
		final static int IDLE = 0;
		final static int RUNNING = 1;
		final static int PAUSE = 2;
		int mStatus = IDLE;
		long mBaseTime;
		long mPauseTime;

		private int mCurRecTimeMs = 0;
		private int mCurProgressTimeDisplay = 0;

		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.mainrecoder);

			mEllapse = (TextView) findViewById(R.id.ellapse);
			mImgNok = (ImageButton) findViewById(R.id.imgbtn_nok);
			/*mImgNok.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					mImgNok.setSelected(true);
				}
			});*/
			mImgStop = (ImageButton) findViewById(R.id.imgbtn_stop);

		}

		public void OnDestory() {
			mTimer.removeMessages(0);
			super.onDestroy();

		}

		Handler mTimer = new Handler() {
			public void handleMessage(Message msg) {
				mEllapse.setText(getEllapse());
				mTimer.sendEmptyMessage(0);
			}

			String getEllapse() {
				long now = SystemClock.elapsedRealtime();
				long ell = now - mBaseTime;
				String sEll = String.format("%02d:%02d:%02d", ell / 1000 / 60,
						(ell / 1000) % 60, (ell % 1000) / 10);
				return sEll;
			}
		};
		
			
		
		public void mOnClick(View v) {
			switch (v.getId()) {
			case R.id.nok:
				onCreate(null);
				break;
			case R.id.play:
				setContentView(R.layout.playlist_main);
				break;
			case R.id.option:
				break;
			case R.id.imgbtn_nok:
				switch (mStatus) {
				case IDLE:
					mBaseTime = SystemClock.elapsedRealtime();
					mTimer.sendEmptyMessage(0);
					mStatus = RUNNING;
					break;
				case RUNNING:
					mTimer.removeMessages(0);
					mPauseTime = SystemClock.elapsedRealtime();
					mStatus = PAUSE;
					break;
				case PAUSE:
					long now = SystemClock.elapsedRealtime();
					mBaseTime += (now - mPauseTime);
					mTimer.sendEmptyMessage(0);
					mStatus = RUNNING;
					break;
				}
				break;
			}
		}
	}


